package com.lc.railway.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.hjq.bar.OnTitleBarListener;
import com.hjq.bar.TitleBar;
import com.hjq.http.EasyHttp;
import com.hjq.http.listener.HttpCallback;
import com.lc.railway.R;
import com.lc.railway.http.request.IssueListsApi;
import com.lc.railway.http.response.IssusBean;
import com.lc.railway.ui.dialog.FieldsDialog;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;

import org.jetbrains.annotations.NotNull;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;

public class IssueActivity extends WaterActivity {
    @BindView(R.id.title_bar_top)
    TitleBar titleBarTop;
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    @BindView(R.id.refreshLayout)
    SmartRefreshLayout refreshLayout;
    private BaseQuickAdapter<IssusBean.DataBeanX.DataBean, BaseViewHolder> issueadapter;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_issue;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
        titleBarTop.setOnTitleBarListener(new OnTitleBarListener() {
            @Override
            public void onLeftClick(View v) {
                finish();
            }

            @Override
            public void onTitleClick(View v) {

            }

            @Override
            public void onRightClick(View v) {
                FieldsDialog dialog=new FieldsDialog(getContext(),IssueActivity.this,"发布榜单");
                dialog.show();
            }
        });
        issueadapter = new BaseQuickAdapter<IssusBean.DataBeanX.DataBean, BaseViewHolder>(R.layout.item_issue) {
            @Override
            protected void convert(@NotNull BaseViewHolder holder, IssusBean.DataBeanX.DataBean dataBean) {
                           holder.setText(R.id.tv_type,dataBean.getTitle());
                holder.setText(R.id.tv_date,dataBean.getCount()+"");

            }
        };
        recyclerView.setAdapter(issueadapter);
        issueadapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@NonNull @NotNull BaseQuickAdapter<?, ?> adapter, @NonNull @NotNull View view, int position) {


                startActivity(new Intent(getContext(),NewsDeatailsActivity.class).putExtra("id",issueadapter.getData().get(position).getId()+"").putExtra("title",issueadapter.getData().get(position).getTitle()).putExtra("type","666"));
            }
        });
        IssueLists();

    }

    private void IssueLists() {
        EasyHttp.post(this)
                .api(new IssueListsApi())
                .request(new HttpCallback<IssusBean>(this) {
                    @Override
                    public void onSucceed(IssusBean data) {

                        if (data.getError_code() == 200) {
                            issueadapter.setNewData(data.getData().getData());
                            issueadapter.notifyDataSetChanged();

                        }
                    }
                });
    }
}
